{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "d9bba13f",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "w= [2.13756953] b= [90.78228498]\n"
     ]
    }
   ],
   "source": [
    "#项目2-例2-1与例2-3代码\n",
    "\n",
    "#训练模型代码\n",
    "#导入numpy与线性回归模型\n",
    "import numpy as np\n",
    "from sklearn.linear_model import LinearRegression\n",
    "\n",
    "#输入训练集数据\n",
    "x=np.array([[100],[113],[90],[89],[60],[70],[50],[45],[55],[78]])\t#房屋面积\n",
    "y=np.array([[301],[324],[285],[296],[200],[260],[300],[120],[180],[245]])\t#售价\n",
    "\n",
    "#建立模型，训练模型\n",
    "model=LinearRegression()\t#建立基于最小二乘法的线性回归模型\n",
    "model.fit(x,y)\t\t\t\t#开始训练模型\n",
    "\n",
    "#求解线性回归方程参数\n",
    "print(\"w=\",model.coef_[0],\"b=\",model.intercept_)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "526e40fb",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAYAAAAEHCAYAAACncpHfAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjUuMSwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/YYfK9AAAACXBIWXMAAAsTAAALEwEAmpwYAAAgUklEQVR4nO3df5xVVb3/8ddnQAKPpqDjKHdAMTEvqXidI4GZlxBETfyBpeA1rVSmH9cMHhaZZpYW6e1CPx5XbRTTdIIHjmiapQ4VSl20hvxxLetrivJDafAnMQHqnM/3j7XH+XVmGHD2Pntmv5+Px3lwztpn9vnMD9ZnrbX3WsvcHRERyZ6yUgcgIiKloQQgIpJRSgAiIhmlBCAiklFKACIiGaUEICKSUUoAIiIZFWsCMLMKM3sser7QzFaa2eVtjncqExGRZMTdA/guMMTMpgMD3H0CcKCZjS5WFnMsIiLSxsC4Tmxmk4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xRpb2n4RbU0GPm9my4EjgGmkZ+mI28xsrJkNAE4jtGbTEhvA34ADo+d54ADSFd+HgUc9TEJJ05IgQ4HDot/rB4HvkJ7YWjwOjATmk66fXYu+uOxLKuKLRj3uAC519xei4lhjS2opiB3m7se2PI+SwCns+NIRcfkm8FPAgHsovtRFKS0EbjazGYQhqonAPSmKbyqhVwLp+tnNA35MGAZaCSxIUWwtvkS4UPhPM7ub9MV3N72z7EuS7iYd8Z1PWBX5MjO7jDBEGmtsfWomcJqXjkhzbJDu+BTbzktjfMViSmOcbaU5vjhj61MJQEREek+arwGIiEiMlABEtsPMBkQXhrs7Xtbm9Sgze08y0YnsPA0BiWyHmX2UcFtyc1R0BPAkUIheDwAuAeYAhxLu1LmBcFtpi5fdfUYC4Yr0mBKAyA6IWvr17n5ch/IhhEk7t7j7yWa2D3Ctu38yOv6Qu/974gGLdCO1t4GKpImZXQVMAAYT1mRZ1ubwPYRWfxUwysxmA890OIVaWpI6ugYg0jNjgBnAU9HzLxJmMl8CvA9YCzwWPX8EeKnYSUTSRAlApGfatuB/Tpgw9s4xd18N7Ef4PzUbeI2wmuPyaCLjiKQCFekpDQGJ7Ljrgb2A97YUmNmuwOeAh4D/Jaxy+u+EZTn2oP3qkyKpoB6AyI57DljToew84Dpgm7t/D3gUqAX2jY59HZGU0V1AIj1gZnWENdrfR2jVvyd6/TLwiLt/MXrffe7+UTP7AbDS3RdFcwhWAJe4+/+W5BsQKUJDQCI9MxA4w91fbltoZkcAF7Yp2tXMDge2uvsiAHdvNrPPEeYIKAFIaqgHICKSUboGICKSUUoAIiIZpQQgIpJRSgAiIhmlBCAiklFKACIiGfX/AcJ9ZXGwW6RMAAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "#绘制图形代码\n",
    "#导入画图工具\n",
    "import matplotlib.pyplot as plt\n",
    "\n",
    "#求模型预测值\n",
    "y2=model.predict(x)\n",
    "\n",
    "#设置坐标轴\n",
    "plt.xlabel('面积')\t\t\t\t\t\t#图形横轴的标签名称\n",
    "plt.ylabel('售价')\t\t\t\t\t\t#图形纵轴的标签名称\n",
    "plt.rcParams['font.sans-serif']='Simhei'\t#中文文字设置为黑体\n",
    "plt.axis([40,125,100,400])\t\t#设置图像横轴与纵轴的最大值与最小值\n",
    "\n",
    "#绘制并显示图像\n",
    "plt.scatter(x,y,s=60,c='k',marker='o')\t#绘制散点图\n",
    "plt.plot(x,y2,'r-')\t\t\t\t\t#绘制直线，第3个参数表示红色实线\n",
    "plt.savefig('pic4-1',dpi=120)\n",
    "plt.show()\t\t\t\t\t\t\t#显示图像\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "7b7f54bd",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "200平方米二手房的预测房价是： 518.2961916987591\n"
     ]
    }
   ],
   "source": [
    "#预测新数据代码\n",
    "a=model.predict([[200]])\n",
    "print(\"200平方米二手房的预测房价是：\",a[0][0])\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "46278df7",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "均方误差为： 1697.4442789901582\n",
      "均方根误差为： 41.200051929459484\n",
      "预测准确率为： 0.8148333769437266\n"
     ]
    }
   ],
   "source": [
    "#评估模型（最小二乘法）\n",
    "\n",
    "#输入测试集\n",
    "x_test=np.array([[103],[115],[90],[89],[60],[70],[50],[45],[55],[78]])\t#房屋面积\n",
    "y_test=np.array([[301],[344],[275],[276],[206],[210],[160],[124],[190],[235]])\t#售价\n",
    "\n",
    "#计算三个值\n",
    "mse=np.average((y2-np.array(y))**2)  #均方误差\n",
    "rmse=np.sqrt(mse)                   #均方根误差\n",
    "r2=model.score(x_test,y_test)      #预测准确率\n",
    "\n",
    "#输出三个值\n",
    "print(\"均方误差为：\",mse)        #输出均方误差\n",
    "print(\"均方根误差为：\",rmse)     #输出均方根误差\n",
    "print(\"预测准确率为：\",r2)         #输出预测准确率\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "5b5b1777",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "fc365246",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
